<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${webname }-登录</title>
<%@ include file="/website/common/common.jsp"%>
<link href="${webctx }/css/login.css" rel="stylesheet" type="text/css" />
</head>
<style>
 .ft-hd-nav{
        padding-top: 20px;
    }
 .login-box {
     width: 100%;
     min-width: 990px;
     height: 600px;
     <%--background: url(${webctx}/images/login-bg.png) no-repeat center;--%>
 }
</style>
<script>
    window.info_photo = "${login_ad}";
</script>
<body rmenu="none">

<%@ include file="/website/common/head_min.jsp"%>

<c:if test="${not empty requesturl}">
<input name="requesturl" type="hidden" value="${requesturl }">
</c:if>
<div id="wrap-main">
    <div class="login-box clearfix">
        <div class="login-con">
            <div class="login-right">
                <div class="login-hd">账号登录</div>
                <div class="login-bd">
                    <div class="bd-item">
                        <div class="item-con">
                            <span class="user-Ico"></span>
                            <input id="wsc-username" name="loginname" type="text" onfocus="inputFocus()" class="item-inp" placeholder="请输入手机号/用户名"/>
                        </div>
                    </div>
                    <div class="bd-item">
                        <div class="item-con">
                            <span class="pass-Ico"></span>
                            <input id="wsc-password" name="pwd" onfocus="inputFocus()" type="password" class="item-inp" placeholder="密码" />
                        </div>
                    </div>
                    <div class="bd-item">
                        <span class="verift-Ico"></span>
                        <div class="yzm-inp"><input name="checkcode" onfocus="inputFocus()" type="text"  placeholder="请输入验证码"/></div>
                        <div class="yzm-pic"><img src="" onclick="getcheckcodeimg()" id="checkcodeimg" style="width:110px;height:40px;cursor:pointer"/></div>
                    </div>
                    <div class="loginmsg"></div>
                    <div class="">
                        <a href="javascript:tologin();" class="login-btn">登录</a>
                    </div>

                    <div class="bd-item-ft clearfix">
                        <span class="fr"><a href="${webctx }/user/findpwd.jsp" class="col666">忘记密码</a></span>
                        <span class="fr"><a href="${webctx}/user/register.jsp" class="col666">马上注册</a></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@ include file="/website/common/foot-site.jsp"%>
</body>
</html>
<script>

    $(function () {
        var img_src = "<%=getRandomFileserver()%>" + info_photo;
        if(info_photo == "") {
            $(".login-box").css("background", "url(${webctx}/images/login-bg.png) no-repeat center");
        } else {
            $(".login-box").css("background", "url("+img_src+") no-repeat center");
        }
    });

    function  inputFocus() {
        $(".loginmsg").text("");
    }
$(function(){
	getcheckcodeimg();
	$(document).keydown(function(event){if (event.keyCode == 13){tologin();}});
})
function getcheckcodeimg(){
	$("#checkcodeimg").attr("src",server+"/validateimg?d="+new Date().getTime());
}
function tologin(){

	if($("[name='loginname']").val()==''){
		$(".loginmsg").text("请输入手机号/用户名！");
		$("[name='loginname']").focus();
	}else if($("[name='pwd']").val()==''){
		$(".loginmsg").text("请输入登录密码！");
		$("[name='pwd']").focus();
	}else{
        saveUserInfo();
		$(".login-btn").html('<img src="'+ctx+'/website/images/rr.gif">');
		$w.httpRequest({
			url:apiroot+"/user/login",
			data:{"loginname":$("[name='loginname']").val(),"pwd":$("[name='pwd']").val(),"checkcode":$("[name='checkcode']").val()},
			ok:function(ret){
				var user=ret.Data;
				$w.setLoginUser(user.userid,user.title,user.phone);
				var tourl="";
				if(sessionStorage.getItem("_curUrl_"))tourl=sessionStorage.getItem("_curUrl_");
				else if($("[name='requesturl']").length>0)tourl=$("[name='requesturl']").val()
				else tourl=ctx;
				if(tourl.indexOf("user/showlogin")!=-1)tourl=ctx+"/website/index.jsp";
				sessionStorage.removeItem("_curUrl_");
				var bl=true;
				try{
					if(sessionStorage.getItem("_newreg_")=='true'){
						bl=false;
						window.location.href=ctx+"/user/certification";
					}
					sessionStorage.removeItem("_newreg_");
				}catch(e){}

                if(bl) {
				    if (tourl.indexOf("user/showregister") != -1 ||tourl.indexOf("user/findpwd") != -1 || tourl == ctx ) {
                        window.location.href= ctx+"/website/index.jsp";
                    } else {
                        window.location.href= tourl;
                    }
                }
			},fail:function(ret){
                var mesDesc = ret.MsgDesc;
                if (mesDesc.indexOf("验证码") != -1) {
                    $(".loginmsg").text("验证码错误或已失效，请重新输入");
                }else {
                    $(".loginmsg").text(mesDesc);
                }
				$(".login-btn").html('登录');
				return false;
			}
		})
	}
}

</script>